package orlowski.kamil.simple.app.service;

import android.app.Activity;
import orlowski.kamil.simple.app.domain.Country;

import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

/**
 * Created by Kamil on 2014-10-16.
 */
public class CountryService implements ICountryService {

    @Override
    public List<Country> getAllCountries(Activity activity) {
        List<Country> result = new LinkedList<Country>();
        String[] locales = Locale.getISOCountries();
        for (int i = 0; i < locales.length; i++) {
            Locale temp = new Locale("", locales[i]);
            int resourceId = activity.getResources().getIdentifier(temp.getCountry().toLowerCase(), "drawable", activity.getPackageName());
            if (resourceId == 0) {
                System.out.println(temp.getCountry() + " " + temp.getDisplayCountry());
            } else {
                result.add(new Country(temp.getCountry(), temp.getDisplayCountry(), resourceId, i));
            }
        }

        return result;
    }

    public int getCos() {
        return 5;
    }
}
